
package com.mibao.defense;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.util.Log;

public class DefenseGlobals
{
    private static final String TAG = "DefenseGlobals";
    public static final String CURRENT_PACKAGE = "com.qihoo360.byod.home";
    public static final String CURRENT_PACKAGE_PREFIX = "com.qihoo360.byod";

    public static int getCurrentUid(Context context)
    {
        return getUidByPackageName(context, CURRENT_PACKAGE);
    }

    private static int getUidByPackageName(Context context, String packageName)
    {
        final PackageManager pm = context.getPackageManager();
        try
        {
            ApplicationInfo info = pm.getApplicationInfo(packageName, 0);
            Log.d(TAG, "DefenseGlobals getUidByPackageName: Uid is "
                    + info.uid + " for package " + packageName);
            return info.uid;
        } catch (NameNotFoundException e)
        {
            Log.e(TAG, "Exception in getUidByPackageName\n" + e.toString());
            return -1;
        }
    }
}
